package com.dance;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author wzm
 * @create 2023-12-15 22:56
 * project_name:web2310
 * @Description
 */
public class A {
    public static void main(String[] args) throws IOException, InterruptedException {
        try{
        int frameCount = 259;
        BufferedImage[] frames = new BufferedImage[frameCount];
        for (int i = 0; i < frameCount; i++) {
            if (i < 10) {
                frames[i] = ImageIO.read(new File("F:\\zhiyin\\1\\1_00" + i + ".png"));

            }
        }
            Thread.sleep(2000);
            // 逐帧打印
            for (int i = 0; i < frameCount; i++) {
                printFrame(frames[i]);

                Thread.sleep(10);
                clearConsole();
            }

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }

    private static void printFrame(BufferedImage frame) {
        StringBuilder sb = new StringBuilder();
        for (int y = 0; y < frame.getHeight(); y += 2) {
            for (int x = 0; x < frame.getWidth(); x++) {
                int pixel = frame.getRGB(x, y);
                int alpha = (pixel >> 24) & 0xff;
                sb.append(alpha > 0 ? "*" : " ");
            }
            sb.append("\n");
        }
        System.out.print(sb.toString());
    }

    private static void clearConsole() {

        System.out.print("\033[H\033[2J");
        System.out.flush();

    }
}
